<?
/**
 * VoiceOne Sounds
 *
 * Frontend to play audio file
 * @package voiceone
 * @subpackage  sounds
 * @todo Needs documentation and implementation
 */
  include ("../../../admin/config/cfg.php");
  global $cwBasePath,$cwlang;

//----------------------------------- GET --------------------------------------
  if(count($_GET)==3){
      // Transfer voicemail message from asterisk's folder to wb's folder
      $ret=$asterisk->mvSoundsFileToSandbox($_GET["id"], $_GET["filename"], $_GET["lang"]);
      if($ret==1){
        // Define relative path (path next to /voiceone_webservices/sandbox) 
        $filepath="/sounds/".$_GET["filename"].".wav";
        // if web service is active the file_content is ready to use
        if($soapWrapper===false){
          $file_content=$asterisk->getFileFromSandbox($filepath);
        }
        // if web service is emulated the file_content have to be decoded
        else{
          $file_content=$asterisk->getFileFromSandbox($filepath);
          $file_content=base64_decode($file_content);
        }
        if($file_content!=""){
          $desc=$_GET["filename"].".wav";
          session_start();
          header('Content-Type: '.'audio/wav');
          header('Content-Disposition: attachment; filename="'.$desc.'"'); 
          echo $file_content;
          exit();
        } 
     }else echo "Error opening audio file: <strong>".$_GET["filename"]."</strong>";
  }
?>
